package com.csc.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csc.bean.BlogLogonBean;
import com.csc.bean.UserRequestBean;
import com.csc.dao.SystemTimeUsedDAO;
import com.csc.dao.SystemTransactionHistoryDAO;
import com.csc.domain.SystemTimeUsed;
import com.csc.domain.TransactionHistory;

@Service
public class SystemTransactionHistoryServiceImpl implements
		SystemTransactionHistoryService {
	@Autowired
	SystemTransactionHistoryDAO transactionHistoryDAO;

	@Autowired
	SystemTimeUsedDAO sysTimeDao;

	public List<TransactionHistory> getListTransactionRequestByAccount() {
		return transactionHistoryDAO.getListTransactionRequestByAccount();
	}

	public List<TransactionHistory> searchAccountRequestTransactionByName(
			String name) {

		return transactionHistoryDAO
				.searchAccountRequestTransactionByName(name);
	}

	public List<TransactionHistory> searchAccountRequestTransactionAdvance(
			String accImpact, String accAffected, String fromDate,
			String toDate, String role, String status) {
		return transactionHistoryDAO.searchAccountRequestTransactionAdvance(
				accImpact, accAffected, fromDate, toDate, role, status);
	}

	public List<TransactionHistory> getListTransactionRequestByAdminReport() {
		return transactionHistoryDAO.getListTransactionRequestByAdminReport();
	}

	public List<TransactionHistory> viewReportActionBySearchUsingUserName(
			String name) {

		return transactionHistoryDAO
				.viewReportActionBySearchUsingUserName(name);
	}

	public List<TransactionHistory> viewReportActionByAdvanceSearch(
			String accImpact, String accAffected, String fromDate,
			String toDate, String role, String status) {
		return transactionHistoryDAO.viewReportActionByAdvanceSearch(accImpact,
				accAffected, fromDate, toDate, role, status);
	}

	/**
	 * @author Nguyen Vu Hung
	 * @return
	 */
	public List<TransactionHistory> getAllInboxUser(String username) {
		return transactionHistoryDAO.getAllInboxUser(username);
	}

	public List<TransactionHistory> searchInboxUserBySender(String userImpact,
			String userAffected) {
		return transactionHistoryDAO.searchInboxUserBySender(userImpact,
				userAffected);
	}

	public List<TransactionHistory> searchInboxUserAdvanced(String affectednam,
			String subject, String fromDate, String toDate) {
		toDate = sysTimeDao.getToDate(toDate);
		fromDate = sysTimeDao.getFromDate(fromDate);
		return transactionHistoryDAO.searchInboxUserAdvanced(affectednam,
				subject, fromDate, toDate);
	}

	// Nguyen Vu Hung - Get list request of user
	public List<TransactionHistory> getListRequestUser(String username) {
		return transactionHistoryDAO.getListRequestUser(username);
	}

	// Nguyen Vu Hung - Parse to UserRequestBean
	public List<UserRequestBean> parseUserRequestBean(
			List<TransactionHistory> listTrans) {
		List<UserRequestBean> listUserRequest = new ArrayList<UserRequestBean>();
		String assignee = "";
		String request = "";
		String message = "";
		String status = "";
		String date = "";
		for (TransactionHistory sysTime : listTrans) {
			assignee = sysTime.getAccAffected().getAccountLoginId();
			request = sysTime.getActionTransaction();
			message = sysTime.getCommand();
			status = sysTime.getSystemStatus().getStatusName();
			date = sysTime.getDateTransaction();

			listUserRequest.add(new UserRequestBean(assignee, request, message,
					status, date));
		}
		return listUserRequest;
	}
}
